package com.pf.utils;

import com.pf.dto.BaseResult;
import com.pf.enums.BaseResultEnum;

public class BaseResultUtils {

    public static <T> BaseResult success(Integer code, String msg, T data) {
        BaseResult<Object> result = new BaseResult<>();
        result.setSuccess(true);
        result.setCode(code);
        result.setMsg(msg);
        result.setStackTraceMsg(null);
        result.setData(data);
        return result;
    }

    /**
     * 调用成功
     *
     * @param <T>
     * @return
     */
    public static <T> BaseResult success(T data) {
        return success(BaseResultEnum.SUCCESS.getCode(), BaseResultEnum.SUCCESS.getMsg(), data);
    }

    /**
     * 调用成功
     *
     * @param <T>
     * @return
     */
    public static <T> BaseResult success() {
        return success(BaseResultEnum.SUCCESS.getCode(), BaseResultEnum.SUCCESS.getMsg(), null);
    }


    /**
     * 调用失败
     *
     * @param code
     * @param msg
     * @param stackTraceMsg
     * @param data
     * @param <T>
     * @return
     */
    public static <T> BaseResult fail(Integer code, String msg, String stackTraceMsg, T data) {
        BaseResult<Object> result = new BaseResult<>();
        result.setSuccess(false);
        result.setCode(code);
        result.setMsg(msg);
        result.setStackTraceMsg(stackTraceMsg);
        result.setData(data);
        return result;
    }

    /**
     * 调用失败
     *
     * @param code
     * @param msg
     * @param <T>
     * @return
     */
    public static <T> BaseResult fail(Integer code, String msg, String stackTraceMsg) {
        return fail(code, msg, stackTraceMsg, null);
    }

    /**
     * 调用失败
     *
     * @param baseResultEnum
     * @param <T>
     * @return
     */
    public static <T> BaseResult fail(BaseResultEnum baseResultEnum) {
        return fail(baseResultEnum.getCode(), baseResultEnum.getMsg(), null);
    }
}
